<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
    String callback = request.getParameter("callback");
	String isShow = request.getParameter("isShow") == null ? "" : request.getParameter("isShow");
	String id = request.getParameter("id") == null ? "" : request.getParameter("id");
	String yet_id = request.getParameter("yet_id") == null ? "" : request.getParameter("yet_id");
	Map<String, Object> sessionMap = (Map<String, Object>) session.getAttribute("LOGIN_USER");
	String person_id = String.valueOf(sessionMap.get("id"));
	String person = String.valueOf(sessionMap.get("truename"));
	boolean isAdd = "".equals(id);
    int flag = 0;
    if(!isAdd){
    	flag = 1;
    }
%>
<html>
	<head>
		<title><%=isAdd?"新建还款":"查看还款单" %></title>
		<script type="text/javascript" src="<%=contextPath %>/public/js/extend.js"></script>
		<style>
			.td1{
				padding-top:10px;
				padding-bottom:5px;
				font-size: 12px;
				background-color: #c0ebd7;
				width:20%;
			}
			.td2{
				padding:5px;
			}
		</style>
	<script type="text/javascript">
	var gdAdminId="";
	var gdAdminName="";
		var lastIndex;
		$(function(){
			jQuery("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			jQuery("#p_dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			jQuery('#company_id').combogrid({
				idField:"id",
				textField:"account",
				title:'公司账户',
				panelWidth:550,
				panelHeight:200,
				rownumbers:true,
				url:'<%=contextPath %>/springMVC/finance/listPageFinanceCompany?flag=1',
				rownumbers:true,
				fitColumns:true,
				singleSelect:true,
				idField:'id',
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true}
				]],
				columns:[[
					{title:'银行',field:'bank',width:200,align:'center'},
					{title:'卡号',field:'account',width:200,align:'center'},
					{title:'开户人',field:'owner',width:100,align:'center'},
					{title:'金额',field:'money',width:100,align:'center'}
				]],
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				toolbar:'#tb1'
			});
			jQuery('#ff').form({
				onLoadSuccess:function(data){
					gdAdminId=data.user_id;
					gdAdminName=data.user_name;
					
				}
			});
			if('<%=flag%>' == 1){
			
		    	jQuery('#ff').form('load','<%=contextPath%>/springMVC/finance/getFinanceLoanById?loan_id=<%=id%>');
				jQuery("#operation_time").datebox('setValue',getTodaySecond());
				
			}else{
			
				jQuery('#ff').form('load','<%=contextPath%>/springMVC/finance/getFinanceLoanYetById?yet_id=<%=yet_id%>');
				
			}
			jQuery('#user_id').combogrid({
				title:'人员选择',
				mode:"remote",
				loadMsg:'正在加载数据，请稍后......',
				panelWidth:550,
				panelHeight:400,
				url:"<%=contextPath%>/springMVC/group/listPageUser",
				idField:"id",
				textField:"truename",
				rownumbers:true,
				fitColumns:true,
				columns: [[
					{field:'id',hidden:true},
					{field:'deptId',hidden:true},
					{field:'truename',title:'姓名',width:100},
					{field:'deptName',title:'所属部门',width:100},
					{field:'privName',title:'角色',width:100}
				]],
				toolbar:"#tb",
				pageSize:10,
				pageList:[10,50,100],  
				pagination:true,
				onChange:function(){
						var row = jQuery('#user_id').combogrid("grid").datagrid('getSelected');
						jQuery('#dept_id').val(row.deptId);
						jQuery('#dept_name').val(row.deptName);
				},
				onLoadSuccess:function(rtJson){
					jQuery('#user_id').combogrid('setValue',gdAdminId);
					jQuery('#user_id').combogrid('setText',gdAdminName);
				}
			});
			});
		function addFinanceLoanRequest(obj){
			
			//自动提交数据
			var user_id=jQuery('#user_id').combogrid('getValue');
			var user_name=encodeURIComponent(jQuery('#user_id').combogrid('getText'));
			if(!checkNullOREmpty(user_id,"申请人")){return;}
			var operation_time=jQuery("#operation_time").datebox('getValue');
			var yet_money = $("#now_money").numberbox("getValue");
			if(yet_money == "" || parseFloat(yet_money) <= 0){
				$.messager.alert('提示','借款总额要大于0 ！');
				return ;
			}
			var company_id = $('#company_id').combotree('getValue');
			if(!checkNullOREmpty(company_id,"所属公司")){return;}
			var summary=encodeURIComponent(jQuery('#remark').val());
			var dept_id=jQuery('#dept_id').val();
			var param = "user_id="+user_id+"&user_name="+user_name+"&operation_time="+operation_time+"&yet_money="+yet_money+"&summary="+summary+"&company_id="+company_id+"&dept_id="+dept_id+"&loan_id=<%=id%>";
			var evlaArr="";
			$.ajax({
				type:'POST',
				url:"<%=contextPath%>/springMVC/finance/addFinanceYetLoan",
				data:param,
				dataType:'json',
				success:function(rtJson){
					if(rtJson.rtState == '0'){
						eval('window.opener.<%=callback%>();');
						window.close();
					}
					else{
						$.messager.alert("提示",rtJson.rtMsrg);
					}
					$(obj).show();
				}
			});
		}
		function doSearch() {
			var dept_id = jQuery('#p_dept_id').combotree('getValue');
			var searchValue = jQuery('#searchValue').val();
			jQuery('#user_id').combogrid("grid").datagrid('load', {
				searchValue : searchValue,
				dept_id:dept_id
			});
		}
	</script>
	</head>
	<body>
		<div style="width: 97%;padding-left:10px">
		<form id="ff">
		<input type="hidden" id="creator" name="creator"/>
			<table  style="border-collapse: collapse;" width="100%" border="1px" bordercolor="#0eb83a">
				<tr>	
				    <td align="right" class="td1" nowrap>还款日期：</td>
					<td class="td2" nowrap >
						<input  id="operation_time" name="operation_time" class="easyui-datebox" data-options="required:true"/>
					</td>		
			        <td align="right" class="td1" nowrap>还款人：</td>
					<td class="td2" nowrap>
						<input type="text" id="user_id" name="user_id"   data-options="required:true"  readonly="readonly">
					</td>
				<tr>
				<tr>
				 <td align="right" class="td1" nowrap>所属部门：</td>
					<td class="td2" nowrap>
						<input type="text" id="dept_id" name="dept_id" hidden="hidden">
						<input type="text" id="dept_name" name="dept_name" data-options="required:true" readonly="readonly">
					</td>
					<td align="right" class="td1" nowrap>借款金额：</td>
					<td class="td2" nowrap >
						 <input id="money" name="money" class="easyui-numberbox" data-options="min:0,precision:2,required:true"  readonly="readonly" value="0"/>
					</td>
				</tr>
					<tr>
				 <td align="right" class="td1" nowrap>已还款金额：</td>
					<td class="td2" nowrap>
						<input type="text" id="yet_money" name="yet_money"  class="easyui-numberbox" data-options="min:0,precision:2,required:true" readonly="readonly"  value="0">
					</td>
					<td align="right" class="td1" nowrap>本次还款额：</td>
					<td class="td2" nowrap >
						 <input id="now_money" name="now_money" class="easyui-numberbox" data-options="min:0,precision:2,required:true"   value="0"/>
					</td>
				</tr>
				<tr>
				<td align="right" class="td1" nowrap>公司账户：</td>
					<td class="td2" nowrap  colspan='3'>
						<input  id="company_id" name="company_id" class="easyui-combotree" data-options="required:true" >
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>摘要：</td>
					<td class="td2" nowrap colspan='3'>
						<textarea  id="remark" name="remark" rows="6" style="width: 100%"></textarea>
					</td>
				</tr>
				<%if(!"1".equals(isShow)){ %>
				<tr>
					<td align="right" class="td1" nowrap></td>
					<td class="td2" nowrap colspan='3'>
						<div align="left">
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:false" onclick="addFinanceLoanRequest(this);">提交</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:false" onclick="javascript:window.close();">关闭</a>
						</div>
					</td>
				</tr>
				<%} %>
				<tr id="tableDiv">
					<td colspan="4"  nowrap>
						<div id="table"></div>
					</td>
				</tr>
			</table>
			</form>
		</div>
		<div id="tb" style="padding:3px;height:auto">
			<div align="right">
			             所属部门：<input  id="p_dept_id" name="p_dept_id"  style="width:150px"  class="easyui-combotree">
				查询条件：<input id="searchValue" name="searchValue" style="width:150px" title="用户名称或者用户真实姓名" placeholder="用户名称或者用户真实姓名"/>
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
	</body>
</html>